In [11]:
!pip install cufflinks
Collecting cufflinks
  Downloading cufflinks-0.12.1.tar.gz (49kB)
Requirement already satisfied: pandas in c:\anaconda3\lib\site-packages (from cufflinks)
Requirement already satisfied: plotly>=2.0.0 in c:\anaconda3\lib\site-packages (from cufflinks)
Collecting colorlover>=0.2 (from cufflinks)
  Downloading colorlover-0.2.1.tar.gz
Requirement already satisfied: python-dateutil>=2 in c:\users\piush\appdata\roaming\python\python35\site-packages (from pandas->cufflinks)
Requirement already satisfied: pytz>=2011k in c:\anaconda3\lib\site-packages (from pandas->cufflinks)
Requirement already satisfied: numpy>=1.7.0 in c:\anaconda3\lib\site-packages (from pandas->cufflinks)
Requirement already satisfied: decorator>=4.0.6 in c:\anaconda3\lib\site-packages (from plotly>=2.0.0->cufflinks)
Requirement already satisfied: nbformat>=4.2 in c:\anaconda3\lib\site-packages (from plotly>=2.0.0->cufflinks)
Requirement already satisfied: requests in c:\anaconda3\lib\site-packages (from plotly>=2.0.0->cufflinks)
Requirement already satisfied: six in c:\users\piush\appdata\roaming\python\python35\site-packages (from plotly>=2.0.0->cufflinks)
Building wheels for collected packages: cufflinks, colorlover
  Running setup.py bdist_wheel for cufflinks: started
  Running setup.py bdist_wheel for cufflinks: finished with status 'done'
  Stored in directory: C:\Users\piush\AppData\Local\pip\Cache\wheels\9d\31\82\40faec2196f9c615b235219f4ae076958c544fa525a4155f42
  Running setup.py bdist_wheel for colorlover: started
  Running setup.py bdist_wheel for colorlover: finished with status 'done'
  Stored in directory: C:\Users\piush\AppData\Local\pip\Cache\wheels\b8\b0\18\76d3f3088cc73950ed1aa44ea074b93ed37309fea57dec78dc
Successfully built cufflinks colorlover
Installing collected packages: colorlover, cufflinks
Successfully installed colorlover-0.2.1 cufflinks-0.12.1
In [12]:
import scipy as sp

import plotly.plotly as py
import cufflinks as cf
import pandas as pd
import numpy as np
print (cf.__version__)

import plotly
plotly.offline.init_notebook_mode() # run at the start of every ipython notebook
0.12.1
In [24]:
#tutorial from
#https://plot.ly/python/ipython-notebook-tutorial/
import plotly.plotly as py
import plotly.figure_factory as ff
import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")
In [29]:
table
Out[29]:
{'data': [{'colorscale': [[0, '#00083e'], [0.5, '#ededee'], [1, '#ffffff']],
   'hoverinfo': 'none',
   'opacity': 0.75,
   'showscale': False,
   'type': 'heatmap',
   'z': [[0, 0, 0, 0],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5],
    [1, 1, 1, 1],
    [0.5, 0.5, 0.5, 0.5]]}],
 'layout': {'annotations': [{'align': 'left',
    'font': {'color': '#ffffff'},
    'showarrow': False,
    'text': '<b>School</b>',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 0,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#ffffff'},
    'showarrow': False,
    'text': '<b>Women</b>',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 0,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#ffffff'},
    'showarrow': False,
    'text': '<b>Men</b>',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 0,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#ffffff'},
    'showarrow': False,
    'text': '<b>Gap</b>',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 0,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'MIT',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 1,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '94',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 1,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '152',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 1,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '58',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 1,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Stanford',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 2,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '96',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 2,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '151',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 2,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '55',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 2,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Harvard',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 3,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '112',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 3,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '165',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 3,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '53',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 3,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'U.Penn',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 4,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '92',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 4,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '141',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 4,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '49',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 4,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Princeton',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 5,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '90',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 5,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '137',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 5,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '47',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 5,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Chicago',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 6,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '78',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 6,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '118',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 6,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '40',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 6,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Georgetown',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 7,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '94',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 7,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '131',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 7,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '37',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 7,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Tufts',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 8,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '76',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 8,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '112',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 8,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '36',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 8,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Yale',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 9,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '79',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 9,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '114',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 9,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '35',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 9,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Columbia',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 10,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '86',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 10,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '119',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 10,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '33',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 10,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Duke',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 11,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '93',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 11,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '124',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 11,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '31',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 11,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Dartmouth',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 12,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '84',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 12,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '114',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 12,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '30',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 12,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'NYU',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 13,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '67',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 13,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '94',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 13,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '27',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 13,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Notre Dame',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 14,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '73',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 14,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '100',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 14,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '27',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 14,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Cornell',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 15,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '80',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 15,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '107',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 15,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '27',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 15,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Michigan',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 16,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '62',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 16,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '84',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 16,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '22',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 16,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Brown',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 17,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '72',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 17,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '92',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 17,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '20',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 17,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Berkeley',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 18,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '71',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 18,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '88',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 18,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '17',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 18,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'Emory',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 19,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '68',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 19,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '82',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 19,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '14',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 19,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'UCLA',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 20,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '64',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 20,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '78',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 20,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '14',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 20,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': 'SoCal',
    'x': -0.45,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 21,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '72',
    'x': 0.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 21,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '81',
    'x': 1.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 21,
    'yref': 'y1'},
   {'align': 'left',
    'font': {'color': '#000000'},
    'showarrow': False,
    'text': '9',
    'x': 2.55,
    'xanchor': 'left',
    'xref': 'x1',
    'y': 21,
    'yref': 'y1'}],
  'height': 710,
  'margin': {'b': 0, 'l': 0, 'r': 0, 't': 0},
  'xaxis': {'dtick': 1,
   'gridwidth': 2,
   'showticklabels': False,
   'tick0': -0.5,
   'ticks': '',
   'zeroline': False},
  'yaxis': {'autorange': 'reversed',
   'dtick': 1,
   'gridwidth': 2,
   'showticklabels': False,
   'tick0': 0.5,
   'ticks': '',
   'zeroline': False}}}
In [25]:
table = ff.create_table(df)
plotly.offline.iplot(table, filename='jupyter/table1')
In [30]:
#Use dataframe.column_title to index the dataframe:
schools = df.School
schools[0]
Out[30]:
'MIT'

Most pandas functions also work on an entire dataframe. For example, calling std() calculates the standard deviation for each column.

In [31]:
df.std()
Out[31]:
Women    12.813683
Men      25.705289
Gap      14.137084
dtype: float64
Plotting Inline

You can use Plotly's python API to plot inside your Jupyter Notebook by calling plotly.plotly.iplot() or plotly.offline.iplot() if working offline. Plotting in the notebook gives you the advantage of keeping your data analysis and plots in one place. Calling the plot with iplot automaticallly generates an interactive version of the plot inside the Notebook in an iframe.

Important

Replace py.iplot with plotly.offline.iplot

In [34]:
import plotly.plotly as py
from plotly.graph_objs import *

data = [Bar(x=df.School,
            y=df.Gap)]

plotly.offline.iplot(data)

Plotting multiple traces and styling the chart with custom colors and titles is simple with Plotly syntax.

Additionally, you can control the privacy with sharing set to public, private, or secret.
In [37]:
trace_women = Bar(x=df.School,
                  y=df.Women,
                  name='Women',
                  marker=dict(color='#ffcdd2'))

trace_men = Bar(x=df.School,
                y=df.Men,
                name='Men',
                marker=dict(color='#A2D5F2'))

trace_gap = Bar(x=df.School,
                y=df.Gap,
                name='Gap',
                marker=dict(color='#59606D'))

data = [trace_women, trace_men, trace_gap]
layout = Layout(title="Average Earnings for Graduates",
                xaxis=dict(title='School'),
                yaxis=dict(title='Salary (in thousands)'))
fig = Figure(data=data, layout=layout)

plotly.offline.iplot(fig)

Now we have interactive charts displayed in our notebook. Hover on the chart to see the values for each bar, click and drag to zoom into a specific section or click on the legend to hide/show a trace.

3D Plotting

In [39]:
import numpy as np

s = np.linspace(0, 2 * np.pi, 240)
t = np.linspace(0, np.pi, 240)
tGrid, sGrid = np.meshgrid(s, t)

r = 2 + np.sin(7 * sGrid + 5 * tGrid)  # r = 2 + sin(7s+5t)
x = r * np.cos(sGrid) * np.sin(tGrid)  # x = r*cos(s)*sin(t)
y = r * np.sin(sGrid) * np.sin(tGrid)  # y = r*sin(s)*sin(t)
z = r * np.cos(tGrid)                  # z = r*cos(t)

surface = Surface(x=x, y=y, z=z)
data = Data([surface])

layout = Layout(
    title='Parametric Plot',
    scene=Scene(
        xaxis=XAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        yaxis=YAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        ),
        zaxis=ZAxis(
            gridcolor='rgb(255, 255, 255)',
            zerolinecolor='rgb(255, 255, 255)',
            showbackground=True,
            backgroundcolor='rgb(230, 230,230)'
        )
    )
)
#Export Static Image Offline using image ='png'
fig = Figure(data=data, layout=layout)
plotly.offline.iplot(fig,image='png')
Plot Controls & IPython widgets
In [40]:
data = [dict(
        visible = False,
        line=dict(color='00CED1', width=6),
        name = '𝜈 = '+str(step),
        x = np.arange(0,10,0.01),
        y = np.sin(step*np.arange(0,10,0.01))) for step in np.arange(0,5,0.1)]
data[10]['visible'] = True

steps = []
for i in range(len(data)):
    step = dict(
        method = 'restyle',
        args = ['visible', [False] * len(data)],
    )
    step['args'][1][i] = True # Toggle i'th trace to "visible"
    steps.append(step)

sliders = [dict(
    active = 10,
    currentvalue = {"prefix": "Frequency: "},
    pad = {"t": 50},
    steps = steps
)]

layout = dict(sliders=sliders)
fig = dict(data=data, layout=layout)

plotly.offline.iplot(fig)

Additional Embed Features

We've seen how to embed Plotly tables and charts as iframes in the notebook, with IPython.display we can embed additional features, such a videos. For example, from YouTube:

In [41]:
from IPython.display import YouTubeVideo
YouTubeVideo("XUNaGFa9xCM")
Out[41]:
In [42]:
import plotly.tools as tls
tls.embed('https://plot.ly/~cufflinks/8')
Out[42]:

Important to make the charts private

In [52]:
#We set the all charts as public
cf.set_config_file(sharing='private',theme='pearl',offline=True)
In [48]:
df = cf.datagen.lines()

print(df)
               JSM.JT    XOA.WJ    GRP.VB     EVM.OX    NQU.IV
2015-01-01   0.632092  0.030552 -0.283261  -1.763005  0.014897
2015-01-02  -0.654996 -0.647577  0.065180  -2.589395 -0.504495
2015-01-03  -2.886012  0.890718 -0.435406  -2.792197 -0.757975
2015-01-04  -2.338030 -0.524345  0.409154  -3.352235 -1.880760
2015-01-05  -3.962908 -0.365147  1.339471  -3.303409 -2.611376
2015-01-06  -4.981078  0.356116  0.366072  -2.386745 -3.365988
2015-01-07  -6.905518  1.273570  0.762925  -1.344454 -3.248506
2015-01-08  -8.585048  1.941117  1.040536  -1.358959 -3.507849
2015-01-09  -8.655581  1.515825  0.711840  -2.458358 -3.573881
2015-01-10  -7.745279  1.715670 -0.438454  -1.906840 -3.512616
2015-01-11  -7.197677  1.942299  0.023004  -1.002010 -0.455555
2015-01-12  -7.947011  2.449490  0.315939  -0.958589 -0.184018
2015-01-13 -10.096415  1.126331  0.302257  -0.878613  2.483699
2015-01-14  -9.982105  2.093707 -0.631220  -1.244396  3.362418
2015-01-15 -10.943708  2.523128 -1.699943  -1.715029  2.805095
2015-01-16 -11.492858  2.262671 -0.025975  -1.879725  3.849781
2015-01-17 -11.069181  3.291831 -0.010147  -1.957107  2.583004
2015-01-18 -11.362268  1.702405 -0.007522  -2.465450  3.295726
2015-01-19 -11.218692  1.586604 -0.003843  -2.996511  3.520508
2015-01-20 -11.903730  2.082389 -0.448649  -1.748009  3.382023
2015-01-21 -12.759869  2.124616 -0.608736  -2.105406  2.078695
2015-01-22 -11.149585  0.666068  0.816752  -1.238425  1.976204
2015-01-23  -8.805085  1.225885  1.280033  -2.191942  2.443128
2015-01-24  -9.617608 -0.038260  1.905399   0.209981  1.590230
2015-01-25  -9.650565 -1.376791  1.781890  -1.353328  2.100967
2015-01-26  -9.995339 -0.182152  4.524849  -1.666864  0.704097
2015-01-27 -11.681424 -0.765844  3.968468  -2.117589  1.455649
2015-01-28 -12.297119 -0.654335  4.401583  -4.212117  3.338204
2015-01-29 -10.734560 -0.422651  5.071145  -6.367168  3.266332
2015-01-30 -10.200773 -0.764937  6.973438  -5.361562  2.702296
...               ...       ...       ...        ...       ...
2015-03-12  -7.800915  8.202871  4.858844  -8.715643  1.036850
2015-03-13  -7.004548  8.382906  5.460848  -8.124881  0.059408
2015-03-14  -6.287767  7.700103  4.866904  -6.965713  1.631549
2015-03-15  -6.274576  5.724574  4.342563  -8.433561  1.862610
2015-03-16  -4.891315  7.750089  3.471997  -9.293131  3.318417
2015-03-17  -3.592309  6.722349  3.440507  -9.484582  2.536877
2015-03-18  -5.107311  6.411157  4.024005  -7.827310  3.620912
2015-03-19  -5.560060  7.456813  4.387908  -7.975385  3.480203
2015-03-20  -3.799153  8.283782  3.450938  -8.242865  2.049144
2015-03-21  -3.679098  7.627759  3.133387  -8.764010  2.684425
2015-03-22  -4.402400  8.104272  1.608075  -8.805379  0.930300
2015-03-23  -5.299620  8.966883  1.386402 -10.330303  0.992711
2015-03-24  -6.526521  9.581368  0.578316 -12.767240  1.779292
2015-03-25  -8.672095  9.274043 -0.220133 -12.003509  0.249168
2015-03-26  -9.733769  9.043792 -0.875200  -9.716970  0.699359
2015-03-27  -9.928686  9.138943  0.342454 -10.535182  1.703317
2015-03-28  -7.740883  8.605954  1.128249 -10.165124  1.257467
2015-03-29  -7.850560  8.519064  0.188374 -10.044153  0.383356
2015-03-30  -7.236579  8.954788  0.430379 -13.291696  1.220654
2015-03-31  -5.482398  8.496910  0.715341 -14.264912 -0.685004
2015-04-01  -3.948018  8.523188  2.083456 -13.197024 -1.778889
2015-04-02  -4.098043  8.650840  2.953726 -12.208562 -1.762226
2015-04-03  -3.707007  6.671974  3.192479 -13.034906 -2.178901
2015-04-04  -1.237077  5.442071  2.388721 -12.265582 -1.809052
2015-04-05  -1.357322  5.783469  3.338113 -11.349465 -1.969802
2015-04-06  -1.935965  7.112566  2.991612 -10.910103 -0.426987
2015-04-07  -2.232921  7.093919  2.316822 -10.352043  1.584799
2015-04-08  -1.205054  7.853487  2.762675 -10.526346  0.364522
2015-04-09  -1.154308  8.006017  3.993025 -10.232602  1.330608
2015-04-10   0.377796  8.943778  4.017433  -8.041911  0.372391

[100 rows x 5 columns]
In [49]:
plotly.offline.iplot([{
    'x': df.index,
    'y': df[col],
    'name': col
}  for col in df.columns], filename='cufflinks/simple-line')

But with cufflinks, you can plot them directly

In [53]:
df.iplot(kind='scatter')
In [55]:
df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
df.scatter_matrix(world_readable= False)

Charts created with cufflinks are synced with your online Plotly account. You'll need to configure your credentials to get started. cufflinks can also be configured to work offline in IPython notebooks with Plotly Offline. To get started with Plotly Offline, download a trial library and run cf.go_offline().

https://plot.ly/ipython-notebooks/cufflinks/#dataframes

In [56]:
df.a.iplot(kind='histogram', world_readable=False)

Chart Types

Line Charts
In [57]:
df = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']).cumsum()
df.iplot(filename='cufflinks/line-example')
Plot one column vs another with x and y keywords
In [58]:
df.iplot(x='A', y='B', filename='cufflinks/x-vs-y-line-example')

Bar Charts

Download some civic data. A time series log of the 311 complaints in NYC.

In [59]:
df = pd.read_csv('https://raw.githubusercontent.com/plotly/widgets/master/ipython-examples/311_150k.csv', parse_dates=True, index_col=1)
df.head(3)
C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2717: DtypeWarning:

Columns (8,39,46,47,48) have mixed types. Specify dtype option on import or set low_memory=False.

Out[59]:
Unique Key Closed Date Agency Agency Name Complaint Type Descriptor Location Type Incident Zip Incident Address Street Name ... Bridge Highway Name Bridge Highway Direction Road Ramp Bridge Highway Segment Garage Lot Name Ferry Direction Ferry Terminal Name Latitude Longitude Location
Created Date
2014-11-16 23:46:00 29300358 11/16/2014 11:46:00 PM DSNY BCC - Queens East Derelict Vehicles 14 Derelict Vehicles Street 11432 80-25 PARSONS BOULEVARD PARSONS BOULEVARD ... NaN NaN NaN NaN NaN NaN NaN 40.719411 -73.808882 (40.719410639341916, -73.80888158860446)
2014-11-16 02:24:35 29299837 11/16/2014 02:24:35 AM DOB Department of Buildings Building/Use Illegal Conversion Of Residential Building/Space NaN 10465 938 HUNTINGTON AVENUE HUNTINGTON AVENUE ... NaN NaN NaN NaN NaN NaN NaN 40.827862 -73.830641 (40.827862046105416, -73.83064067165407)
2014-11-16 02:17:12 29297857 11/16/2014 02:50:48 AM NYPD New York City Police Department Illegal Parking Blocked Sidewalk Street/Sidewalk 11201 229 DUFFIELD STREET DUFFIELD STREET ... NaN NaN NaN NaN NaN NaN NaN 40.691248 -73.984375 (40.69124772858873, -73.98437529459297)

3 rows × 51 columns

In [60]:
series = df['Complaint Type'].value_counts()[:20]
series.head(3)
Out[60]:
HEAT/HOT WATER            32202
Street Light Condition     7558
Blocked Driveway           6997
Name: Complaint Type, dtype: int64
In [61]:
series.iplot(kind='bar', yTitle='Number of Complaints', title='NYC 311 Complaints',
             filename='cufflinks/categorical-bar-chart')
Plot a dataframe row as a bar
In [63]:
df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
row = df.ix[5]
row.iplot(kind='bar')

Call iplot(kind='bar') on a dataframe to produce a grouped bar chart

In [65]:
df.iplot(kind='bar', filename='cufflinks/grouped-bar-chart')
In [66]:
df.iplot(kind='bar', barmode='stack')

Remember: plotly charts are interactive. Click on the legend entries to hide-and-show traces, click-and-drag to zoom, double-click to autoscale, shift-click to drag

Make your bar charts horizontal with kind='barh'
In [67]:
df.iplot(kind='barh',barmode='stack', bargap=.1)
Themes

cufflinks ships with a few themes. View available themes with cf.getThemes, apply them with cf.set_config_file

In [68]:
cf.getThemes()
Out[68]:
['henanigans', 'space', 'white', 'polar', 'pearl', 'solar', 'ggplot']
In [78]:
cf.set_config_file(theme='polar')

Histograms

In [79]:
df = pd.DataFrame({'a': np.random.randn(1000) + 1,
                   'b': np.random.randn(1000),
                   'c': np.random.randn(1000) - 1})

df.iplot(kind='histogram')

Customize your histogram with

  • barmode (overlay | group | stack)
  • bins (int)
  • histnorm ('' | 'percent' | 'probability' | 'density' | 'probability density')
  • histfunc ('count' | 'sum' | 'avg' | 'min' | 'max')
In [71]:
df.iplot(kind='histogram', barmode='stack', bins=100, histnorm='probability')

Like every chart type, split your traces into subplots or small-multiples with subplots and optionally shape. More on subplots below.

In [80]:
df.iplot(kind='histogram', subplots=True, shape=(3, 1))

Box Plots

In [81]:
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
df.iplot(kind='box')

Area Charts

To produce stacked area plot, each column must be either all positive or all negative values. When input data contains NaN, it will be automatically filled by 0. If you want to drop or fill by different values, use dataframe.dropna() or dataframe.fillna() before calling plot.

In [82]:
df.iplot(kind='area', fill=True)
For non-stacked area charts, set kind=scatter with fill=True
In [83]:
df.iplot(fill=True)
Scatter Plot

Set x and y as column names. If x isn't supplied, df.index will be used.

In [84]:
df = pd.read_csv('http://www.stat.ubc.ca/~jenny/notOcto/STAT545A/examples/gapminder/data/gapminderDataFiveYear.txt', sep='\t')
df2007 = df[df.year==2007]
df1952 = df[df.year==1952]

df2007.iplot(kind='scatter', mode='markers', x='gdpPercap', y='lifeExp', filename='cufflinks/simple-scatter')
Plotting multiple column scatter plots isn't as easy with cufflinks. Here is an example with Plotly's native syntax
In [86]:
fig = {
    'data': [
        {'x': df2007.gdpPercap, 'y': df2007.lifeExp, 'text': df2007.country, 'mode': 'markers', 'name': '2007'},
        {'x': df1952.gdpPercap, 'y': df1952.lifeExp, 'text': df1952.country, 'mode': 'markers', 'name': '1952'}
    ],
    'layout': {
        'xaxis': {'title': 'GDP per Capita', 'type': 'log'},
        'yaxis': {'title': "Life Expectancy"}
    }
}
plotly.offline.iplot(fig, filename='cufflinks/multiple-scatter')
Grouping isn't as easy either. But, with Plotly's native syntax:
In [87]:
plotly.offline.iplot(
    {
        'data': [
            {
                'x': df[df['year']==year]['gdpPercap'],
                'y': df[df['year']==year]['lifeExp'],
                'name': year, 'mode': 'markers',
            } for year in [1952, 1982, 2007]
        ],
        'layout': {
            'xaxis': {'title': 'GDP per Capita', 'type': 'log'},
            'yaxis': {'title': "Life Expectancy"}
        }
}, filename='cufflinks/scatter-group-by')
Bubble Charts

Add size to create a bubble chart. Add hover text with the text attribute.

In [88]:
df2007.iplot(kind='bubble', x='gdpPercap', y='lifeExp', size='pop', text='country',
             xTitle='GDP per Capita', yTitle='Life Expectancy',
             filename='cufflinks/simple-bubble-chart')

Subplots

subplots=True partitions columns into separate subplots. Specify rows and columns with shape=(rows, cols) and share axes with shared_xaxes=True and shared_yaxes=True.

In [89]:
df=cf.datagen.lines(4)
df.iplot(subplots=True, shape=(4,1), shared_xaxes=True, fill=True, filename='cufflinks/simple-subplots')

Add subplot titles with subplot_titles as a list of titles or True to use column names.

In [90]:
df.iplot(subplots=True, subplot_titles=True, legend=False)

Scatter matrix

In [91]:
df.scatter_matrix(filename='cufflinks/scatter-matrix-subplot', world_readable=True)

Heatmaps

In [92]:
cf.datagen.heatmap(20,20).iplot(kind='heatmap',colorscale='spectral',
                                filename='cufflinks/simple-heatmap')

Lines and Shaded Areas

Use hline and vline for horizontal and vertical lines.

In [93]:
df=cf.datagen.lines(3,columns=['a','b','c'])
In [94]:
df.iplot(hline=[2,4],vline=['2015-02-10'])

Draw shaded regions with hspan

In [95]:
df.iplot(hspan=[(-1,1),(2,5)], filename='cufflinks/shaded-regions')

Extra parameters can be passed in the form of dictionaries, width, fill, color, fillcolor, opacity

In [96]:
df.iplot(vspan={'x0':'2015-02-15','x1':'2015-03-15','color':'rgba(30,30,30,0.3)','fill':True,'opacity':.4}, 
         filename='cufflinks/custom-regions')

Customizing Figures

cufflinks is designed for simple one-line charting with Pandas and Plotly. All of the Plotly chart attributes are not directly assignable in the df.iplot call signature. To update attributes of a cufflinks chart that aren't available, first convert it to a figure (asFigure=True), then tweak it, then plot it with plotly.plotly.iplot. Here is an example of a simple plotly figure.

In [98]:
from plotly.graph_objs import *
plotly.offline.iplot({
    'data': [
        Bar(**{
            'x': [1, 2, 3],
            'y': [3, 1, 5],
            'name': 'first trace',
            'type': 'bar'
        }),
        Bar(**{
            'x': [1, 2, 3],
            'y': [4, 3, 6],
            'name': 'second trace',
            'type': 'bar'
        })
    ],
    'layout': Layout(**{
        'title': 'simple example'
    })
}, filename='cufflinks/simple-plotly-example')

cufflinks generates these figure's that describe plotly graphs. For example, this graph:

In [99]:
df.iplot(kind='scatter', filename='cufflinks/simple-scatter-example')

has this description:

In [100]:
figure = df.iplot(kind='scatter', asFigure=True)
print(figure.to_string())
Figure(
    data=Data([
        Scatter(
            x=['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04', '..'  ],
            y=array([ -2.21247606e+00,  -2.53856724e+00,  -3.27999079e+00,
 ..,
            line=Line(
                color='rgba(0, 128, 240, 1.0)',
                dash='solid',
                width=1.3
            ),
            mode='lines',
            name='a',
            text=''
        ),
        Scatter(
            x=['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04', '..'  ],
            y=array([-0.20319488,  1.35975532,  1.78453768,  2.22146555,  1...,
            line=Line(
                color='rgba(238, 118, 0, 1.0)',
                dash='solid',
                width=1.3
            ),
            mode='lines',
            name='b',
            text=''
        ),
        Scatter(
            x=['2015-01-01', '2015-01-02', '2015-01-03', '2015-01-04', '..'  ],
            y=array([ -0.94308995,   0.2000632 ,   1.03148502,   0.92547415,..,
            line=Line(
                color='rgba(48, 144, 84, 1.0)',
                dash='solid',
                width=1.3
            ),
            mode='lines',
            name='c',
            text=''
        )
    ]),
    layout=Layout(
        legend=Legend(
            bgcolor='#F2F3F7',
            font=Font(
                color='#505050'
            )
        ),
        paper_bgcolor='#F2F3F7',
        plot_bgcolor='#F2F3F7',
        titlefont=dict(
            color='#484848'
        ),
        xaxis1=XAxis(
            gridcolor='#E1E5ED',
            showgrid=True,
            tickfont=dict(
                color='#505050'
            ),
            title='',
            titlefont=dict(
                color='#505050'
            ),
            zerolinecolor='#E1E5ED'
        ),
        yaxis1=YAxis(
            gridcolor='#E1E5ED',
            showgrid=True,
            tickfont=dict(
                color='#505050'
            ),
            title='',
            titlefont=dict(
                color='#505050'
            ),
            zerolinecolor='#E1E5ED'
        )
    )
)

So, if you want to edit any attribute of a Plotly graph from cufflinks, first convert it to a figure and then edit the figure objects. Let's add a yaxis title, tick suffixes, and new legend names to this example:

In [103]:
figure['layout']['yaxis1'].update({'title': 'Price', 'tickprefix': '$'})
for i, trace in enumerate(figure['data']):
    trace['name'] = 'Trace {}'.format(i)
    
plotly.offline.iplot(figure, filename='customized-chart.html')
In [ ]: